/*
    name 获取函数名
*/
function add(a, b) {
  return a + b;
}

console.log("函数的名称为", add.name);

/*
    length 函数参数的个数
*/
console.log("函数参数的个数", add.length);

/*
    apply
*/

let obj = {
  age: 19,
  name: "hello",
};

let obj2 = {
  sayAge() {
    console.log(this.age);
  },
  getSum(arr) {
    //ps:通过apply传入的参数在arguments上面
    console.log("传入的参数为", arguments);
    // 不在形参arr里

    //arguments是类数组，所以要先转化
    let nums = [...arguments];
    let sum = nums.reduce((cur, next) => cur + next, 0);
    console.log("和的值为", sum);
  },
};

obj2.sayAge.apply(obj);

obj2.getSum.apply(obj, [1, 2, 3, 4]);

obj2.getSum.apply(null, [1, 2, 3]);

obj2.getSum.call(obj, 1, 2, 3, 4);

function log(...args) {
  console.log(this, ...args);
}

//字符串也有this
const logBind = log.bind("hello", 1, 2, 3);

//连续绑定
const bindFn1 = logBind.bind("hello world", 5, 6);

bindFn1(7, 8);

let objX = {
  get latest() {
    return "bar";
  },
};

console.log(objX.latest);

console.log(objX.latest);
